package com.jiang.gzjp.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.jiang.gzjp.struts.form.LoginForm;

/** 
 * MyEclipse Struts
 * Creation date: 02-27-2019
 * 
 * XDoclet definition:
 * @struts.action path="/login" name="loginForm" input="/login.jsp" scope="request" validate="true"
 */
public class LoginAction extends Action {

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
			HttpServletResponse response) {
		LoginForm loginForm = (LoginForm) form;// 主要是使用ActionForm去接收参数值
		// 然后调用Service层，最后路由
		String username = loginForm.getUsername();
		String password = loginForm.getPassword();
		if("jzw".equalsIgnoreCase(username) && "123456".equalsIgnoreCase(password)){
			// 登入成功
			// 成功信息返回前端
			 request.setAttribute("msg", super.getResources(request).getMessage("login.success"));
			 return mapping.findForward("success");
		}else{
			request.setAttribute("msg", super.getResources(request).getMessage("login.failure"));
			// 登入失败
			return 	mapping.findForward("failure");
		}
	}
}